import { isNotEmpty } from '@jecloud/utils';
/**
 * 关键字高亮，返回富文本节点
 * @param {*} param0
 * @returns
 */
export function keywordToRichText({ text, keyword, style = '', ellipsis = 0 }) {
  // 折行
  const ellipsisCls = ellipsis > 0 ? `je-line-ellipsis-${ellipsis}` : '';
  let html = text;
  if (isNotEmpty(text) && isNotEmpty(keyword)) {
    const splitStr = '`__`';
    const texts = text
      .replace(new RegExp(keyword, 'gm'), splitStr + keyword + splitStr)
      .split(splitStr);
    html = texts
      .map((str) => {
        return str === keyword
          ? `<span class="je-keyword-highlight" style="${style}">${str}</span>`
          : str;
      })
      .join('');
  }
  return `<div class='${ellipsisCls}'>${html}</div>`;
}
/**
 * 获取当前页面信息
 * @returns
 */
export function getCurrentPage() {
  // eslint-disable-next-line no-undef
  const pages = getCurrentPages();
  return pages[pages.length - 1];
}
